<template>
  <div class="container">
    <div class="empty"
         v-if="isempty">
      <img src="/static/teeth/no_bank.png"
           mode="widthFix"
           alt=""
           class="nothing">
      <p class="msg">您还没有添加银行卡</p>
    </div>
    <ul class="card-list"
        v-else>
      <li class="list-item clearfix"
          @tap="select(item)"
          v-for="(item, index) in list_data"
          :key="index">
          <img class="bank_bj" src="/static/teeth/bank_bj_01.png"/>
        <div class="header clearfix">
          <div class="logo">
            <img :src="imgUrl+item.bank_images_logo"
                 alt=""
                 class="logo-img">
          </div>
          <div class="info">
            <div class="bank-name">
              {{item.cbin_bank}}
            </div>
            <div class="card-type">
              {{item.cbin_card_type}}
            </div>
          </div>
        </div>
        <div class="card-num">
          ****&nbsp;&nbsp;&nbsp;&nbsp;****&nbsp;&nbsp;&nbsp;&nbsp;****&nbsp;&nbsp;&nbsp;&nbsp;{{item.card_num}}
        </div>
      </li>
    </ul>
    <a class="add-btn"
       href="/pages/package_mine/add_bankcard/main">
      <span class="icon">+</span> 添加银行卡
    </a>
  </div>
</template>


<script>
import common from "@/assets/js/mmk_common.js";
import imageUrl from "@/assets/js/image.js";
export default {
  data () {
    return {
      list_data: [],
      loop: true,
      imgUrl: imageUrl,
      isempty: true,
      page_status: 0 // 页面状态，0为初始状态，1为选择银行卡状态
    };
  },
  methods: {
    get_data () {
      common.mmk_Loading(0)
      common.fly_post("api/v4_5/user_cards/index", {
        page: 1,
        pageSize: 100
      }, result => {
        common.mmk_Loading(1)
        let res = result.data;
        if (res.status_code == 0) {
          if (res.data.length > 0) {
            this.isempty = false;
            res.data.forEach(element => {
              element.card_num = element.card_num.substr(-4);
            });
            this.list_data = res.data;
          } else {
            this.isempty = true;
          }
        } else {
          common.mmk_Loading(1)
          common.mmk_Loading(2, res.message)
        }
      })
    },
    select (item) {
      if (!this.page_status) {
        wx.navigateTo({
          url: `/pages/package_mine/bankcard_detail/main?name=${item.cbin_bank}
        &num=${item.card_num}&type=${item.cbin_card_type}&logo=${item.bank_images_logo}
        &bgImg=${item.bank_images_background}&id=${item.id}`
        });
        return false;
      } else {
        wx.setStorageSync("card_data", JSON.stringify(item));
        wx.navigateBack({
          delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
        });
      }

    }
  },

  onLoad (options) {
    wx.setNavigationBarTitle({
      title: "银行卡"
    });
    if (options.status) {
      this.page_status = options.status;
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff", //前景颜色值，包括按钮、标题、状态栏的颜色，仅支持 #ffffff 和 #000000,
      backgroundColor: "#444444", //背景颜色值，有效值为十六进制颜色,
      success: res => { }
    });
    // this.get_data();
  },
  onShow () {
    this.get_data();
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  padding: 15px 15px 0;
  background-color: #F5F6F7;
  box-sizing: border-box;
  position: relative;
  .card-list {
    margin: 0 auto;
    padding-bottom: 60px;
    .list-item {
      width: 345px;
      height: 115px;
      position: relative;
      margin-bottom: 15px;
      .bank_bj{
         width: 345px;
         height: 115px;
        position: absolute;
        top: 0;
        left: 0;
      }
      .header {
        position: absolute;
        left: 26px;
        top: 20px;
        .logo {
          float: left;
          width: 36px;
          height: 36px;
          border-radius: 50%;
          .logo-img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
          }
        }
        .info {
          float: left;
          margin-left: 16px;
          .bank-name {
            font-size: 17px;
            font-family: "PingFangSC-Regular";
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
          }
          .card-type {
            font-size: 12px;
            font-family: "PingFangSC-Regular";
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
          }
        }
      }
      .card-num {
        margin-top: 80px;
        font-size: 17px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
        text-align: center;
      }
    }
  }
  .add-btn {
    width: 351px;
height: 50px;
background: #FFFFFF;
box-shadow: 0px 8px 14px 0px rgba(14,26,128,0.03);
border-radius: 4px;
filter: blur(0px);
position: fixed;
bottom: 2%;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #606972;
line-height: 17px;
    .icon {
      font-weight: bold;
      width: 19px;
height: 19px;
background: #3EB0A9;
box-shadow: 0px 3px 4px 0px rgba(211,211,211,0.47);
color: #fff;
line-height: 17px;
border-radius: 50%;
text-align: center;
margin-right: 6px;
    }
  }
  .empty {
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    .nothing {
      width: 122px;
      display: block;
      margin-bottom: 10px;
    }
    .msg {
      font-size: 14px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>

